package com.wy._05Random.randomFile;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

//随机文档  可以指定格式，文件大小等等参数
public class RandomDocument {
    public static void crateFileTxt(String location, String fileName) {
        final int fileSizeInBytes = 50 * 1024; // 50 KB
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(location + fileName))) {
            Random random = new Random();
            String characters = "abcdefghijklmnopqrstuvwxyz ";
            int charactersLength = characters.length();
            int currentSize = 0;

            while (currentSize < fileSizeInBytes) {
                // Write a random character
                char c = characters.charAt(random.nextInt(charactersLength));
                writer.write(c);
                currentSize++;
                // Check size in bytes (approximation: 1 char = 1 byte)
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
